<?php
include_once("../../php/include_all.php");
$tahun=date('Y');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../../css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
<div class="row-fluid sortable">
	<div class="box span 12 geo-box">
    	<div class="box-header well" ><h2>SPLIT USULAN</h2></div>
        <form class="form-horizontal" id="usulan">
        <div class="box-content">
        	<table class="table-awal">
            	<tr>
                	<td>SKPD</td>
                    <td>
                    	<select name="skpd" id="skpd" class="skpd">
                            <option id="0">-Pilih SKPD-</option>
                            <?php
                                $skpd = get_datas('select * from mus_skpd');
                                foreach($skpd as $skpd){
                            ?>
                            <option value="<?php echo $skpd['id_skpd']?>"><?php echo $skpd['nama_skpd']?></option>
                            <?php
                            }
                            ?>
                        </select>
                        <span id='alerti' style='margin-left: 13px;padding-bottom:3px;'></span>
                    </td>
                </tr>
                
            </table>
            <br>
            <table class="table table-bordered" align="center" width="100%">
            	<thead>
                	<tr>
                    	<th>NO</th>
                    	<th>PROGRAM / KEGIATAN</th>
                    	<th>INDIKATOR HASIL PROGRAM</th>
                    	<th>INDIKATOR KELUARAN</th>
                    	<th>INDIKATOR HASIL KEGIATAN</th>
                    	<th>TARGET</th>
                    	<th>SKPD TUJUAN</th>
                    </tr>
                </thead>
                <?php
					
				?>
                <tbody id="tbody-split">
                </tbody>
            </table>
        <div class="pull-right">
            <span id='loader' style='width:30px;height:30px;'></span><button type="button" class="btn btn-primary btn-simpan-usulan"><i class="icon-white icon-check"></i>&nbsp;Simpan</button>
        </div>
        &nbsp;  
        </div>
        </form> 
    </div>
</div>
<div id="windowRincPro" class="modal hide fade" style="width:1140px;left:35%;" valign="midle" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<header class="modal-header">
    	<a href="#" class="close" data-dismiss="modal">x</a>
        <h5>Kegiatan : <span id="titlekeg"></span></h5>
    </header>
    <form class="form-horizontal" id="rin_keg">
    <div class="modal-body" id="rinc_keg">
    	<table class="table table-bordered table-striped geo-table">
        	<thead>
            	<tr>
                	<th>NO</th>
                	<th>LOKASI</th>
                	<th>VOLUME</th>
                	<th>APBD KAB</th>
                	<th>APBD PROV</th>
                	<th>APBN</th>
                	<th>PRIORITAS</th>
                </tr>
            </thead>
            <tbody id="rincian_keg">
            </tbody>
        </table>
    </div>
    </form>
    <div id='loading' style='z-index: 1000; border: medium none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background-color: #515151; opacity: 0.6; position: fixed;'></div>
</div>
<script type="text/javascript">
	var urls = 'tools.php';
	function showrincian(a){
        var aa = $(a);
        var di = a.name;
        var wind = $('#windowRincPro');
        $('#titlekeg').html(aa.html());
        var load = $('#loading');
        var tbl = $('#rincian_keg');
        load.removeClass().addClass('BigSnakeSpiner');

        var post = $.post(urls, {act: 'rincProg', id: di});
        post.done(function(res) {
            load.css('display', 'none');            
            tbl.html(res);
            //statusFunction();
            init();
        });
	}
	function init (){
        $('#skpd').change(function() {
            var idSKK = this.value;
            if (idSKK > 0) {
                var post = $.post(urls, {act: 'tampil_laporan', idskpd: idSKK});
                post.done(function(inc) {
                    var isi = inc.split('___');
                    if (isi.length === 2) {
                        if (isi[0] == 'ok') {
                            $('#tbody-split').html(isi[1]);
                        } else if (isi[0] == 'err') {
                            $('#alerti').removeClass().addClass('alert alert-error');
                            $('#alerti').html('Error  !!!' + isi[1]);
                            setTimeout(function() {
                                $('#alerti').removeClass();
                                //$('#alerti').html('');
                            }, 1500);
                        }
                    } else {
                        $('#alerti').removeClass().addClass('alert alert-error');
                        $('#alerti').html('Gagal Mengambil data !!!');
                        setTimeout(function() {
                            $('#alerti').removeClass();
                            $('#alerti').html('');
                        }, 1500);
                    }

                });
            }
        });
        $('.btn-simpan-usulan').click(function() {
            var btn = $(this);
            var load = $('#loader');
            var rslt = $('#result');
            //var wind = $('#windowRincPro');

            load.addClass('spinner pull-left');
			load.removeClass();
            var form = $('#usulan');
            var data = form.serializeArray();
            var post = $.post(urls, data);            
            post.done(function(res) {
                // 0-> no data; 1-> ok; 2-> error
                var result = res.split('__');
                if (result.length == 2) {
                    if (result[0] == 'success') {
                        rslt.html('<font color="green">Tersimpan...</font>');
                        setTimeout(function() {
                            rslt.html('');
                            //wind.modal('hide');
                        }, 2000);
						var tbody = $('#tbody-split');   
						tbody.html('');
						init();                    
                    
                    } else {
                        rslt.html('<font color="#000">Tidak ada data</font>');
                        load.removeClass();
                        setTimeout(function(){
                            rslt.html('');
                        },2000);
                    }
                } else {
                    rslt.html('<font color="red">' + res + '</font>');
                }
            });
        });
	}
	init();
</script>
</body>
</html>
